Publicize TreeEntryDefinition.From() overloads#547
Conversation
How about rather adding a new overload
Can't we use the existing |
👍
Not sure how I overlooked that... yes. You could have just told me I was an idiot in the other PR. 😊 |
|
🙉 🙈 🙊 Much smaller change for your consideration. |
|
@dahlbyk Nice! I was wondering if could take a fresh look at
Last request: Could you please cover with some test this new overload. Imaginary bonus points if it demonstrates how simpler this makes the history rewriting process. |
Beyond the tests already included? I can add a filter-branch test as an example, too... |
This seems like the direction to go, with |
@dahlbyk A "wrapped" Tree is an already existing odb Tree. Once, you start altering it, by adding, removing or modifying any of its content, it "unwraps" (and also unwraps its parent Trees if any) and it's tracked as an entry in the Adding a new TreeEntryDefinition automatically replaces the potentially existing one. As such, Considering this, I think it's safe to remove the call to diff --git a/LibGit2Sharp/TreeDefinition.cs b/LibGit2Sharp/TreeDefinition.cs
index 7426a28..63bbb0c 100644
--- a/LibGit2Sharp/TreeDefinition.cs
+++ b/LibGit2Sharp/TreeDefinition.cs
@@ -29,7 +29,7 @@ public static TreeDefinition From(Tree tree)
foreach (TreeEntry treeEntry in tree)
{
- td.AddEntry(treeEntry.Name, TreeEntryDefinition.From(treeEntry));
+ td.Add(treeEntry.Name, treeEntry);
}
return td; |
Done |
|
Rebased on latest. Also added a test that shows rewriting history to always use a specific version of a |
|
I love it! Let's squash this! 🔨 |
|
Squashed first two...figure the last can stand alone. |
|
Thanks 🍌 |

Branched from #511. As written there:
My desired behavior was essentially "inject cleansed file from a branch" into earlier trees. Without
TreeEntryDefinition.From(te), I have to do something like:Not a huge deal, but I resent the extra work. Things would get even more complicated if you're dealing with more than one type of
TreeEntry.The first commit has the two overloads I think we definitely need:
From(TreeEntry treeEntry)for the case above, where we just want to use an existingTreeEntry.From(ObjectId objectId)since we can't naturally get access to aSubmoduleinstance during a rewrite.The second commit includes the other two overloads, for completeness. I can't think of a reason we would need to publicize either, since they align with existing
TreeDefinition.Add(...)overloads, but I'm not sure it hurts to expose them if the others are too.